<div class="crudField crud_text">
	#{field 'object.subrubro'}
	<label for="${field.id}"> Subrubro </label>
	<select id="object_subrubro" name="object.subrubro.id">
		<option value="">&{'crud.none'}</option> 
		#{list items:_subrubros, as:'subrubro'}
			<option value="${subrubro.id}" #{if (_selected !=null&& subrubro.id.equals(_selected.id))} selected #{/if}>${subrubro.descripcion}</option>
		#{/list}
	</select>
	#{ifError field.name}
	<span class="error">${field.error.raw()}</span>
	#{/ifError} #{/field}
</div>
<script type="text/javascript">
function getRamas() {
	$.get("/Ramas/getRamasJson",  {
		sector: $("#object_sector").val()
	},function(data){
		if(data[0] != 'ERROR'){
			var ramas = JSON.parse(data[1]);
			
			$("select#object_rama > option").remove();
			var i = 0;
			for(i = 0; i < ramas.length; i++) {
				$("select#object_rama").append("<option value='" + ramas[i].id + "' >" + ramas[i].descripcion + "</option>");
			}
			
			$("select#object_rama").prepend('<option value="" selected="selected">&{'crud.none'}</option>');
			
			return false;
		}else {
			return false;
		}
		
	},'json');
	$("select#object_rubro > option").remove();
	$("select#object_rubro").prepend('<option value="" selected="selected">&{'crud.none'}</option>');
	$("select#object_subrubro > option").remove();
	$("select#object_subrubro").prepend('<option value="" selected="selected">&{'crud.none'}</option>');
}
function getRubros() {
	$.get("/Rubros/getRubrosJson",  {
		rama: $("#object_rama").val()
	},function(data){
		if(data[0] != 'ERROR'){
			var rubros = JSON.parse(data[1]);
			
			$("select#object_rubro > option").remove();
			var i = 0;
			for(i = 0; i < rubros.length; i++) {
				$("select#object_rubro").append("<option value='" + rubros[i].id + "' >" + rubros[i].descripcion + "</option>");
			}
			
			$("select#object_rubro").prepend('<option value="" selected="selected">&{'crud.none'}</option>');
			
			return false;
		}else {
			return false;
		}
		
	},'json');
	$("select#object_subrubro > option").remove();
	$("select#object_subrubro ").prepend('<option value="" selected="selected">&{'crud.none'}</option>');
}
function getSubrubros() {
	$.get("/Subrubros/getSubrubrosJson",  {
		rubro: $("#object_rubro").val()
	},function(data){
		if(data[0] != 'ERROR'){
			var subrubros = JSON.parse(data[1]);
			
			$("select#object_subrubro > option").remove();
			var i = 0;
			for(i = 0; i < subrubros.length; i++) {
				$("select#object_subrubro").append("<option value='" + subrubros[i].id + "' >" + subrubros[i].descripcion + "</option>");
			}
			
			$("select#object_subrubro").prepend('<option value="" selected="selected">&{'crud.none'}</option>');
			
			return false;
		}else {
			return false;
		}
		
	},'json');
}
</script>